import request from '../plugins/request';

interface DynamicData {
    id: string;
    content: string;
    images?: string[];
    likes: number;
    comments: number;
    user: {
        id: string;
        username: string;
        avatarUrl: string;
    };
}

interface ApiResponse<T> {
    code: number;
    message?: string;
    data: T;
}

// 动态相关接口
export const addDynamic = (data: { content: string; images?: string[] }): Promise<ApiResponse<DynamicData>> => {
    return request.post('/dynamic/add', data);
};

export const deleteDynamic = (dynamicId: string): Promise<ApiResponse<null>> => {
    return request.post(`/dynamic/delete/${dynamicId}`);
};

export const getDynamicList = (params: { pageSize?: number; pageNum?: number } = {}): Promise<ApiResponse<DynamicData[]>> => {
    return request.get('/dynamic/list', { params });
};

export const getDynamicDetail = (id: string) => {
    return request.get(`/dynamic/get/${id}`);
};

// 评论相关接口
export const addComment = (data: any) => {
    return request.post('/comment/add', data);
};

export const deleteComment = (commentId: string) => {
    return request.post(`/comment/delete/${commentId}`);
};

export const getCommentList = (dynamicId: string) => {
    return request.get(`/comment/list/${dynamicId}`);
};

// 点赞相关接口
export const addLike = (data: { dynamicId: string; liked: boolean }) => {
    return request.post('/dynamic/like', data);
};

// 分享相关接口
export const addShare = (data: any) => {
    return request.post('/share/add', data);
};

export const deleteShare = (shareId: string) => {
    return request.post(`/share/delete/${shareId}`);
};